package com.hulk.ratel.config.interceptor;

import com.hulk.ratel.common.util.IDWorkerRadix;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Author: hulk
 * @Date: 2018/5/21 21:10
 */
@Deprecated
@Slf4j
//@Aspect
//@Component
public class MDCAespect {

    @Around(value = "execution(* com.hulk.ratel..*.*(..))")
    public Object logMDC(ProceedingJoinPoint jp) throws Throwable {
        Object result = null;
        try {
            MDC.put("mdc_trace_id",  new StringBuilder("<").append(IDWorkerRadix.getDtmId().toUpperCase()).append(">").toString() );
            result = jp.proceed();
            //MDC.remove("mdc_trace_id");
        } catch (Throwable e) {
            log.error("mdc error", e);
            throw e;
        } finally {
            MDC.remove("mdc_trace_id");
        }
        return result;
    }
}
